#include <Bounce2.h>//按键检测库 用这个检测单按很准
#include <lvgl.h>
#include <Arduino.h>

uint8_t wifi_time = 0;//记录wifi开启的时间(分钟)
uint8_t wifi_time_status = 0;//记录wifi开关状态 0 关   1开

Bounce2::Button k1 = Bounce2::Button();//实例化一个抖动对象
Bounce2::Button k2 = Bounce2::Button();//实例化一个抖动对象
Bounce2::Button k3 = Bounce2::Button();//实例化一个抖动对象
Bounce2::Button k4 = Bounce2::Button();//实例化一个抖动对象

void my_key_init(){
// 9 8 7 6      k1.2.3.4
k1.attach(9, INPUT_PULLUP);
k1.interval(5);//间隔是5ms
k2.attach(8, INPUT_PULLUP);
k2.interval(5);//间隔是5ms
k3.attach(7, INPUT_PULLUP);
k3.interval(5);//间隔是5ms
k4.attach(6, INPUT_PULLUP);
k4.interval(5);//间隔是5ms
}
void my_key_update(){
k1.update();//更新
k2.update();//更新
//k3.update();//更新
k4.update();//更新
}

//旋转编码器的回调函数
static void encoder_read(lv_indev_t * indev, lv_indev_data_t*data){  
my_key_update();//按键状态更新
if(k1.pressed()){data->enc_diff = 1;}
if(k2.pressed()){data->enc_diff = -1;}
//if(k3.pressed()){data->state = LV_INDEV_STATE_PRESSED;digitalWrite(15,LOW);}else{data->state = LV_INDEV_STATE_RELEASED;}
if(!digitalRead(7)){data->state = LV_INDEV_STATE_PRESSED;}else{data->state = LV_INDEV_STATE_RELEASED;}

if(k4.pressed()){ 
  if(WiFi.status() != WL_CONNECTED){
    tian_wifi_init();wifi_time_status = 1;
        for(uint8_t cg4 = 1;cg4<20;cg4++){ get_day_tianqi();get_hour_tianqi();  if(Status_code=="ok"){goto go4;}  delay(100);     }
           go4 :;
          _ui_label_set_property(ui_Label28,_UI_LABEL_PROPERTY_TEXT,String("WIFI已打开").c_str());
          if(Status_code!="ok"){_ui_label_set_property(ui_Label28,_UI_LABEL_PROPERTY_TEXT,String("WIFI已打开,天气更新失败").c_str());}
      
                                   }
    else{
      tian_wifi_end();  _ui_label_set_property(ui_Label28,_UI_LABEL_PROPERTY_TEXT,String("WIFI已关闭").c_str()); wifi_time = 0;wifi_time_status = 0;
        }    
               }

if(wifi_time_status==1&&wifi_time>=5) { tian_wifi_end();wifi_time = 0;wifi_time_status = 0; _ui_label_set_property(ui_Label28,_UI_LABEL_PROPERTY_TEXT,String("WIFI已自动关闭").c_str());}


}









